package com.appcloner.navigation

import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.appcloner.ui.card.CardVerificationScreen
import com.appcloner.ui.cloner.AppClonerScreen
import com.appcloner.ui.home.HomeScreen

@Composable
fun AppNavHost(navController: NavHostController) {
    NavHost(
        navController = navController,
        startDestination = "card_verification"
    ) {
        composable("card_verification") {
            CardVerificationScreen(
                onCardVerified = {
                    navController.navigate("home") {
                        popUpTo("card_verification") { inclusive = true }
                    }
                }
            )
        }
        
        composable("home") {
            HomeScreen(
                onAppSelected = { packageName ->
                    navController.navigate("cloner/$packageName")
                }
            )
        }
        
        composable("cloner/{packageName}") { backStackEntry ->
            val packageName = backStackEntry.arguments?.getString("packageName") ?: ""
            AppClonerScreen(
                packageName = packageName,
                onBackPressed = {
                    navController.popBackStack()
                }
            )
        }
    }
}
